<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
    <title><?php echo C('WEBSITE_NAME');?></title>
    <?php if(!preg_match('/(MSIE 7.0)/', $_SERVER['HTTP_USER_AGENT'])){ echo '<link href="//cdn.bootcss.com/pace/1.0.2/themes/orange/pace-theme-flash.css" rel="stylesheet">'; echo '<script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>'; } ?>
    <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/2.3.2/css/bootstrap.min.css" />
	<link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/3.2.1/css/font-awesome.min.css" />
    <link rel="stylesheet" href="/css/admin.css" />
    <script src="//cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
	<!-- 顶部 -->
	<div class="sys-header">
		<div class="inner">
			<div class="system-name"><?php echo session('user.shop_name'); ?></div>
			<div class="box_message">
				<ul class="top_tool">
					<!-- <li class="message_all"><a><i class="icon-envelope icon-white"></i> 消息<span>(0)</span></a></li> -->
					<li class="set_all"><a href="<?php echo __MODULE__; ?>/index/aliOAuth"><i class="icon-time icon-white"></i> 1688授权有效期：<?php echo \Admin\Controller\IndexController::getAccessTime() ?>天</a></li>
					<li class="set_all"><a href="javascript:win.modal('<?php echo __MODULE__; ?>/index/modifyAccount')"><i class="icon-user icon-white"></i> <?php echo session('user.username'); ?></a></li>
					<li class="set_all"><a href="javascript:win.modal('<?php echo __MODULE__; ?>/index/modifyPwd')"><i class="icon-lock icon-white"></i> 修改密码</a></li>
					<li class="exit_soft"><a href="<?php echo __MODULE__; ?>/login/out"><i class="icon-off icon-white"></i> 退出</a></li>
				</ul>
			</div>
		</div>
	</div>
	<div class="body">
		<div class="col-side">
	    	<?php \Common\Common\Auth::get()->showMenuHtml() ?>
    	</div>
	    <div class="col-main">
	    	<div class="navbar menu-group">
			    <ul class="nav">
	    		  <?php echo \Common\Common\Auth::get()->showMenuGroup() ?>
			    </ul>
			</div>
			<div class="content-container"><div id="sellerSendModal" class="form-horizontal modal hide fade send-modal modal-middle" aria-hidden="true" style="width: 650px;">
	<div class="modal-header ">
	    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
	    <h3 id="myModalLabel">商品发货</h3>
	</div>
	<div class="modal-body">
		<input type="hidden" id="js-tid" value="<?php echo ($trade["tid"]); ?>">
		<table id="" class="table" data-toggle="table">
	       <thead>
	           <tr>
	               <th><input type="checkbox" checked="checked" id="select_all_product"></th>
	               <th>产品</th>
	               <th style="width:60px">数量</th>
	               <th style="width:120px">物流</th>
	               <th style="width:120px">快递单号</th>
	           </tr>
	       </thead>
	       <tbody>
	       	<?php if(is_array($orders)): foreach($orders as $key=>$product): ?><tr>
	       		<td class="item-checkbox">
	       			<?php if($product['status'] == 'send'): ?><input type="checkbox" checked="checked" disabled="disabled" value="<?php echo ($product["oid"]); ?>">
	       			<?php else: ?>
	       			<input type="checkbox" checked="checked" value="<?php echo ($product["oid"]); ?>" class="js-checkbox"><?php endif; ?>
	       		</td>
	            <td><?php echo ($product["title"]); ?><span style="color:#f60"> <?php echo ($product["spec"]); ?></span></td>
	            <td>
	            <?php if($product['status'] == 'send'): echo ($product["num"]); ?>
	            <?php else: ?>
	            	<input type="text" value="<?php echo ($product["num"]); ?>" style="width:20px;text-align:center" data-max="<?php echo ($product["num"]); ?>" class="js-num"><?php endif; ?>
	            </td>
	            <td><?php echo ($product["express_name"]); ?></td>
	            <td><?php echo ($product["express_no"]); ?></td>
	           </tr><?php endforeach; endif; ?>
		</tbody>
	   </table>
	   <div>
		   <div class="control-group">
				<label class="control-label">收货人</label>
				<div class="controls" style="padding-top: 5px;">
					<?php echo ($trade["receiver_name"]); ?>，<?php echo ($trade["receiver_mobile"]); ?>
				</div>
			</div>
		   	<div class="control-group">
				<label class="control-label">收货地址</label>
				<div class="controls" style="padding-top: 4px;">
					<?php echo ($trade["receiver_province"]); ?> <?php echo ($trade["receiver_city"]); ?> <?php echo ($trade["receiver_county"]); ?>，
					<?php echo ($trade["receiver_detail"]); ?>
				</div>
			</div>
			<div class="control-group">
		           <label class="control-label">发货方式</label>
		           <div class="controls">
		               <label class="radio inline">
		                   <input type="radio" name="shipping_type" value="express" checked="" onclick="changeExpressType(&quot;express&quot;)">快递发货
		               </label>
		               <label class="radio inline">
		                   <input type="radio" name="shipping_type" value="selffetch" onclick="changeExpressType(&quot;selffetch&quot;)">上门自提
		               </label>
						<label class="radio inline">
		                   <input type="radio" name="shipping_type" value="virtual" onclick="changeExpressType(&quot;virtual&quot;)">无需物流
		               </label>
		           </div>
		    </div>
			<div class="control-group express_info">
				<label class="control-label must">物流公司</label>
				<div class="controls">
					<select name="express_id" class="required" style="width:160px">
						<option value="">请选择物流公司</option>
						<?php if(is_array($express_list)): foreach($express_list as $exp_id=>$express): if($exp_id > 10): ?><option value="<?php echo ($exp_id); ?>"><?php echo ($express["name"]); ?></option><?php endif; endforeach; endif; ?>
					</select>
					<input type="text" maxlength="20" name="express_no" placeholder="快递单号" class="required">
				</div>
			</div>
		</div>
	</div>
	<div class="modal-footer">
	    <button type="button" class="btn btn-primary js-ok" style="width: 100px;">发货</button>
	</div>
	<script type="text/javascript">
	//切换发货方式
	function changeExpressType(type){
		var $express_type = type;
		if($express_type == 'express'){
			$(".express_info").show().find('select, input').removeClass('ignore');
		}else{
			$(".express_info").hide().find('select, input').addClass('ignore');
		}
	}
	
	(function() { 
		var $sellerSendModal = $('#sellerSendModal');
		$sellerSendModal.modal();
		
		$sellerSendModal.find('.js-ok').on('click', function(){
			var tid = $("#js-tid").val()
			var $checkboxs = $sellerSendModal.find('table>tbody>tr .js-checkbox:checked');
			var data = {products:{}};
			var reg = /^\+?[1-9][0-9]*$/;
			data.shipping_type = $("input[name='shipping_type']:checked").val();
			if(data.shipping_type == "express"){
				data.express_id = $("select[name='express_id'] option:selected").val();
				data.express_no = $("input[name='express_no']").val()
				if(data.express_id == ""){
					alert("请选择物流公司！");
					return false;
				}
				if(data.express_no == ""){
					alert("请填写物流单号！");
					return false;
				}else if(data.express_no.length < 6){
					alert("物流单号长度必须为6位以上！");
					return false;
				}
			}
			
			var total = 0;
			for(var i=0; i<$checkboxs.length; i++){
				var $checkbox = $checkboxs.eq(i);
				var $tr = $checkbox.parent().parent();
				var oid = $checkbox.val();
				var $num = $tr.find('.js-num');
				var num = $num.val();
				var max = $num.data('max');
				if(!reg.test(num)){
					alert("发货数量必须为大于0的整数！");
					return false;
				}
				if(num > max){
					alert("发货数量大于订单数量！");
					return false;
				}
				total++;
				data.products[oid] = num;
			};
			
			if(total == 0){
				alert('请勾选要发货的产品');
				return false;
			}

			 $.ajax({
					url: '<?php echo __ACTION__; ?>?tid='+tid,
					type: 'post',
					data: data,
					dataType:'json',
					success: function(order){
						$sellerSendModal.trigger('send.success', [order]);
						$sellerSendModal.modal('hide');
			 		}
				});
			 
			return false;
		});
		
		$sellerSendModal.on('hidden', function(){
			$sellerSendModal.remove();
		});
		
		//全选反选
		$('#select_all_product').on('click', function(event){
			$sellerSendModal.find('table>tbody>tr>td>.js-checkbox').prop('checked', this.checked);
		});
	})();
	</script>
</div>




	
</div>
	    </div>
	</div>
	<div class="footer">
		<div class="copyright">
			<div class="ft-copyright"></div>
		</div>
	</div>
	<div class="back-to-top">
	    <a href="javascript:;" class="js-back-to-top"><i class="icon-chevron-up"></i>返回顶部</a>
	</div>
	<script src="/js/common.js"></script>
	<script src="/js/gridview.js"></script>
	<script src="//cdn.bootcss.com/bootstrap/2.3.2/js/bootstrap.min.js"></script>
</body>
</html>